import sys
sys.path.append("..")
from database.db_handler import MysqlHander
from common.my_http import MyHttp
import urllib.request
from bs4 import BeautifulSoup
from common.entity_data import EntityData
import glob
import jieba
import re
import threading
import hashlib

'''
品牌
'''

class ZhongkeyuanYuanshiData:
    def __init__(self):
        self.entity = EntityData()
        self.url_map = {}
        pass
    
    def get_data(self):
        url = "http://casad.cas.cn/ysxx2017/ysmdyjj/qtysmd_124280/"
        bs4_data = MyHttp.bs4_utf8_data(url)
        #dts = bs4_data.find(name="div", attrs={'class':'contentTest'}).find_all("dt")
        dds = bs4_data.find(name="div", attrs={'class':'contentTest'}).find_all("dd")
        name_set = ""
        for i in range (0, len(dds)):
            for d in dds[i].find_all("a"):
                name_set += "|" + d.text

        print("中科院院士:" + name_set)
        self.entity.add_entity_data("中国科学院院士", "", 200, 2000005, "中科院", "", name_set)
        self.entity.update_entity_data("中国科学院院士", "", 200, 2000005, "中科院", "", name_set)

    def get_data2(self):
        url = "http://casad.cas.cn/ysxx2017/wjysmdyjj/"
        bs4_data = MyHttp.bs4_utf8_data(url)
        #dts = bs4_data.find(name="div", attrs={'class':'contentTest'}).find_all("dt")
        dds = bs4_data.find(name="div", attrs={'class':'contentTest'}).find_all("dd")
        name_set = ""
        for i in range (0, len(dds)):
            for d in dds[i].find_all("a"):
                name_set += "|" + d.text.split("（")[0]

        print("中科院外籍院士:" + name_set)
        self.entity.add_entity_data("中国科学院外籍院士", "", 200, 2000005, "中科院", "", name_set)
        self.entity.update_entity_data("中国科学院外籍院士", "", 200, 2000005, "中科院", "", name_set)


def zhongkeyuan_yuanshi_api():
    d = ZhongkeyuanYuanshiData()
    d.get_data()
    d.get_data2()

if __name__ == '__main__':
    zhongkeyuan_yuanshi_api()
